<?php
if ( ! defined('__TYPECHO_ROOT_DIR__'))
{
    exit;
}
include 'Tyupoo.php';
$pluginOptions = $options->plugin('Tyupoo');
$typ = new Tyupoo(
				  $pluginOptions->apiKey,
				  $pluginOptions->sharedSecret,
				  $pluginOptions->authToken);

$out['urlAlbum']		= Helper::url('Tyupoo/album.php');
$out['urlUpload']		= Helper::url('Tyupoo/upload.php');

if ( ! empty($_FILES['imgfile']))
{
	$fileinfo 		= $_FILES['imgfile'];
	$albumId 		= ($_POST['album'] === 'null') ? '' : $_POST['album'];
	$title   		= empty($_POST['title']) ? $fileinfo['name'] : $_POST['title'];
	$description 	= $_POST['description'];
	$tags 			= $_POST['tags'];
	$photos 		= $typ->upload($fileinfo['tmp_name'], $fileinfo['type'], $albumId, $title, $description, $tags);
	$out['photoList'] 		= $photos;
	$out['photoListJson']   = json_encode($photos);
	$out['photoLen']		= count($photos);
	$out['photoPages']  	= 0;//ceil($out['photoLen'] / 8);
	include 'template/uploadOk.php';
	exit();
}

$userID = $pluginOptions->userID;
$albumList = $typ->getAlbumList($userID);
if (is_array($albumList))
{
	$albumList[] = array(
		'id' 	=> 'null',
		'title' => '默认相册',
	);
}
$out['albumList']    	= $albumList;
$out['albumCurrent']	= 'null';

include 'template/upload.php';
?>